using System;
using System.Text;
using System.Windows.Forms;

namespace ctsu.Admin.Forms.CoreLab
{
	public class TestBatchCreateEditDlg : System.Windows.Forms.Form
	{
		public delegate void ButtonClickEventHandler(object sender, EditBatchEventArgs e);
		public event ButtonClickEventHandler ButtonClick;
		#region controls
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.CheckBox chkAll;
		private System.Windows.Forms.CheckBox chk3;
		private System.Windows.Forms.CheckBox chk4;
		private System.Windows.Forms.CheckBox chk5;
		private System.Windows.Forms.CheckBox chk2;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TextBox SmallNote;
		private System.Windows.Forms.Button btnClear;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnReplaceAll;
		private System.Windows.Forms.Button btnReplaceAllMatch;
		private System.Windows.Forms.Button btnFindNext;
		private System.Windows.Forms.Button btnReplaceSelected;
		private System.Windows.Forms.ComboBox TestType;
		private System.Windows.Forms.TextBox DrawID;
		private System.Windows.Forms.ComboBox UnitOfMeasure;
		private System.Windows.Forms.CheckBox chk6;
		private System.Windows.Forms.TextBox textBox1;
		private System.ComponentModel.Container components = null;
		#endregion controls

		public TestBatchCreateEditDlg()
		{
			InitializeComponent();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.chk6 = new System.Windows.Forms.CheckBox();
			this.chkAll = new System.Windows.Forms.CheckBox();
			this.chk3 = new System.Windows.Forms.CheckBox();
			this.chk4 = new System.Windows.Forms.CheckBox();
			this.chk5 = new System.Windows.Forms.CheckBox();
			this.chk2 = new System.Windows.Forms.CheckBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.UnitOfMeasure = new System.Windows.Forms.ComboBox();
			this.SmallNote = new System.Windows.Forms.TextBox();
			this.btnClear = new System.Windows.Forms.Button();
			this.TestType = new System.Windows.Forms.ComboBox();
			this.DrawID = new System.Windows.Forms.TextBox();
			this.btnClose = new System.Windows.Forms.Button();
			this.btnReplaceAll = new System.Windows.Forms.Button();
			this.btnReplaceAllMatch = new System.Windows.Forms.Button();
			this.btnFindNext = new System.Windows.Forms.Button();
			this.btnReplaceSelected = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.chk6);
			this.groupBox1.Controls.Add(this.chkAll);
			this.groupBox1.Controls.Add(this.chk3);
			this.groupBox1.Controls.Add(this.chk4);
			this.groupBox1.Controls.Add(this.chk5);
			this.groupBox1.Controls.Add(this.chk2);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(112, 167);
			this.groupBox1.TabIndex = 9;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Replace Columns";
			// 
			// chk6
			// 
			this.chk6.Location = new System.Drawing.Point(8, 136);
			this.chk6.Name = "chk6";
			this.chk6.Size = new System.Drawing.Size(96, 24);
			this.chk6.TabIndex = 12;
			this.chk6.Text = "Comments";
			// 
			// chkAll
			// 
			this.chkAll.Location = new System.Drawing.Point(8, 16);
			this.chkAll.Name = "chkAll";
			this.chkAll.Size = new System.Drawing.Size(96, 24);
			this.chkAll.TabIndex = 1;
			this.chkAll.Text = "All columns";
			// 
			// chk3
			// 
			this.chk3.Location = new System.Drawing.Point(8, 64);
			this.chk3.Name = "chk3";
			this.chk3.Size = new System.Drawing.Size(88, 27);
			this.chk3.TabIndex = 3;
			this.chk3.Text = "Test Type";
			// 
			// chk4
			// 
			this.chk4.Location = new System.Drawing.Point(8, 88);
			this.chk4.Name = "chk4";
			this.chk4.Size = new System.Drawing.Size(88, 24);
			this.chk4.TabIndex = 4;
			this.chk4.Text = "Units";
			// 
			// chk5
			// 
			this.chk5.Location = new System.Drawing.Point(8, 112);
			this.chk5.Name = "chk5";
			this.chk5.Size = new System.Drawing.Size(88, 24);
			this.chk5.TabIndex = 5;
			this.chk5.Text = "Label Note";
			// 
			// chk2
			// 
			this.chk2.Location = new System.Drawing.Point(8, 40);
			this.chk2.Name = "chk2";
			this.chk2.Size = new System.Drawing.Size(88, 24);
			this.chk2.TabIndex = 2;
			this.chk2.Text = "Draw ID";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.textBox1);
			this.groupBox2.Controls.Add(this.UnitOfMeasure);
			this.groupBox2.Controls.Add(this.SmallNote);
			this.groupBox2.Controls.Add(this.btnClear);
			this.groupBox2.Controls.Add(this.TestType);
			this.groupBox2.Controls.Add(this.DrawID);
			this.groupBox2.Enabled = false;
			this.groupBox2.Location = new System.Drawing.Point(120, 8);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(184, 167);
			this.groupBox2.TabIndex = 10;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Replace All Rows Matching";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(8, 136);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(168, 22);
			this.textBox1.TabIndex = 134;
			// 
			// UnitOfMeasure
			// 
			this.UnitOfMeasure.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.UnitOfMeasure.Location = new System.Drawing.Point(8, 84);
			this.UnitOfMeasure.Name = "UnitOfMeasure";
			this.UnitOfMeasure.Size = new System.Drawing.Size(168, 24);
			this.UnitOfMeasure.TabIndex = 133;
			// 
			// SmallNote
			// 
			this.SmallNote.Location = new System.Drawing.Point(8, 111);
			this.SmallNote.Name = "SmallNote";
			this.SmallNote.Size = new System.Drawing.Size(168, 22);
			this.SmallNote.TabIndex = 132;
			// 
			// btnClear
			// 
			this.btnClear.Location = new System.Drawing.Point(80, 16);
			this.btnClear.Name = "btnClear";
			this.btnClear.Size = new System.Drawing.Size(75, 24);
			this.btnClear.TabIndex = 131;
			this.btnClear.Text = "Clear";
			// 
			// TestType
			// 
			this.TestType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.TestType.Location = new System.Drawing.Point(8, 57);
			this.TestType.Name = "TestType";
			this.TestType.Size = new System.Drawing.Size(168, 24);
			this.TestType.TabIndex = 130;
			// 
			// DrawID
			// 
			this.DrawID.Location = new System.Drawing.Point(8, 32);
			this.DrawID.Name = "DrawID";
			this.DrawID.Size = new System.Drawing.Size(48, 22);
			this.DrawID.TabIndex = 0;
			// 
			// btnClose
			// 
			this.btnClose.Location = new System.Drawing.Point(352, 152);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(75, 24);
			this.btnClose.TabIndex = 20;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnReplaceAll
			// 
			this.btnReplaceAll.Location = new System.Drawing.Point(312, 48);
			this.btnReplaceAll.Name = "btnReplaceAll";
			this.btnReplaceAll.Size = new System.Drawing.Size(144, 24);
			this.btnReplaceAll.TabIndex = 19;
			this.btnReplaceAll.Text = "Replace all";
			this.btnReplaceAll.Click += new System.EventHandler(this.btnReplaceAll_Click);
			// 
			// btnReplaceAllMatch
			// 
			this.btnReplaceAllMatch.Enabled = false;
			this.btnReplaceAllMatch.Location = new System.Drawing.Point(312, 112);
			this.btnReplaceAllMatch.Name = "btnReplaceAllMatch";
			this.btnReplaceAllMatch.Size = new System.Drawing.Size(144, 24);
			this.btnReplaceAllMatch.TabIndex = 18;
			this.btnReplaceAllMatch.Text = "Replace all matching ";
			// 
			// btnFindNext
			// 
			this.btnFindNext.Enabled = false;
			this.btnFindNext.Location = new System.Drawing.Point(312, 80);
			this.btnFindNext.Name = "btnFindNext";
			this.btnFindNext.Size = new System.Drawing.Size(144, 24);
			this.btnFindNext.TabIndex = 17;
			this.btnFindNext.Text = "Find next match";
			// 
			// btnReplaceSelected
			// 
			this.btnReplaceSelected.Location = new System.Drawing.Point(312, 16);
			this.btnReplaceSelected.Name = "btnReplaceSelected";
			this.btnReplaceSelected.Size = new System.Drawing.Size(168, 24);
			this.btnReplaceSelected.TabIndex = 16;
			this.btnReplaceSelected.Text = "Replace Selected Row(s)";
			this.btnReplaceSelected.Click += new System.EventHandler(this.btnReplaceSelected_Click);
			// 
			// TestBatchCreateEditDlg
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(490, 184);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnReplaceAll);
			this.Controls.Add(this.btnReplaceAllMatch);
			this.Controls.Add(this.btnFindNext);
			this.Controls.Add(this.btnReplaceSelected);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "TestBatchCreateEditDlg";
			this.Text = "Create Test Labels - Batch Editor";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox2.PerformLayout();
			this.ResumeLayout(false);

		}
		#endregion

		//		public bool Initialize()
		//		{
		//			StringBuilder sb = new StringBuilder();
		//			try
		//			{
		//				//Forms.Utils.LoadCbo(TestType,"TestType_L",true);
		//
		//			}
		//			catch(Exception ex)
		//			{
		//				sb.Append("Could not load test type list for Edit Batch Dialog");
		//				sb.Append(Environment.NewLine);
		//				sb.Append("Error: " + ex.Message);
		//				//bool b = ////ExceptionPolicy.HandleException(ex, "Exception Policy");
		//				MessageBox.Show(this, sb.ToString(),"Edit Batch Dialog Error",MessageBoxButtons.OK, MessageBoxIcon.Stop);
		//				return false;
		//			}		
		//			return true;
		//		}

		private void btnReplaceSelected_Click(object sender, System.EventArgs e)
		{
			EditBatchEventArgs eva;
			eva = SetEventArgs();

			if (!VerifyReplaceColumns(eva))
				return;

			eva.ButtonName = "ReplaceSelected";
			if (ButtonClick != null)
				ButtonClick(this, eva);
		}

		private void btnReplaceAll_Click(object sender, System.EventArgs e)
		{
			EditBatchEventArgs eva;
			eva = SetEventArgs();

			if (!VerifyReplaceColumns(eva))
				return;

			StringBuilder sb = new StringBuilder("You are about to replace 'ALL' rows for selected columns with changes.");
			sb.Append(Environment.NewLine);
			sb.Append("Press 'Yes' to continue.");
			if (MessageBox.Show(this, sb.ToString(), "Confirm To Continue", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
				return;

			eva.ButtonName = "ReplaceAll";
			if (ButtonClick != null)
				ButtonClick(this, eva);
		}

		private bool VerifyReplaceColumns(EditBatchEventArgs eva)
		{
			foreach (bool b in eva.ReplaceColumns)
			{
				if (b)
				{
					return true;
				}
			}
			MessageBox.Show(this, "Select a replacement column", "Select Replacement Column", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			return false;
		}

		private EditBatchEventArgs SetEventArgs()
		{
			EditBatchEventArgs e = new EditBatchEventArgs();

			e.ReplaceColumns[0] = chkAll.Checked;
			e.ReplaceColumns[1] = chk2.Checked;
			e.ReplaceColumns[2] = chk3.Checked;
			e.ReplaceColumns[3] = chk4.Checked;
			e.ReplaceColumns[4] = chk5.Checked;
			e.ReplaceColumns[5] = chk6.Checked;

			return e;
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

	}
}
